<!DOCTYPE html>
<html  lang="zh-CN" >
    <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1, maximum-scale=5, viewport-fit=cover">
    <title>shadowsocks安装以及kcptun加速 | 在路上</title>
    <meta name="description" content="shadowsocks安装以及kcptun加速">
<meta property="og:type" content="article">
<meta property="og:title" content="shadowsocks安装以及kcptun加速">
<meta property="og:url" content="http://www.lushunming.com.cn/2017/03/09/linux/2017-03-09-shadowsocks%E5%AE%89%E8%A3%85%E4%BB%A5%E5%8F%8Akcptun%E5%8A%A0%E9%80%9F/index.html">
<meta property="og:site_name" content="在路上">
<meta property="og:description" content="shadowsocks安装以及kcptun加速">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://raw.githubusercontent.com/xtaci/kcptun/master/kcptun.png">
<meta property="article:published_time" content="2017-03-08T16:00:00.000Z">
<meta property="article:modified_time" content="2019-11-24T07:17:53.636Z">
<meta property="article:author" content="machine">
<meta property="article:tag" content="linux">
<meta property="article:tag" content="shadowsocks">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://raw.githubusercontent.com/xtaci/kcptun/master/kcptun.png">

    
    <link rel="icon" href="/images/favicon.ico" type="image/x-icon">

    
<link rel="stylesheet" href="/css/common.min.css">



    
    
    
        <link href="//cdn.jsdelivr.net/npm/gitalk@1.4.0/dist/gitalk.min.css" rel="stylesheet">
    
    
        <link href="//cdn.jsdelivr.net/npm/lightgallery.js@1.1.3/dist/css/lightgallery.min.css" rel="stylesheet">
    
    
    
<link rel="stylesheet" href="/css/iconfont.min.css">

    
<meta name="generator" content="Hexo 5.1.1"></head>

    <body>
        <header class="header header-fixture">
    <div class="profile-search-wrap flex sm:block">
        
        
        <div class="profile sm:text-center md:px-1 lg:px-3 sm:pb-4 sm:pt-6">
            <a id="avatar" role="link" href="https://www.lushunming.com.cn" class="inline-block lg:w-16 lg:h-16 w-8 h-8 m-2" target="_self" rel="noopener" rel="noreferrer" >
                <img src="/images/avatar.jpg" class="rounded-full" alt="avatar">
            </a>
            <h2 id="name" class="hidden lg:block">lushunming</h2>
            <h3 id="title" class="hidden xl:block">前码农</h3>
            
            <small id="location" class="hidden lg:block">
                <i class="iconfont icon-map-icon"></i>
                泰州
            </small>
            
        </div>
        
        
<div class="search flex-1 flex lg:inline-block sm:hidden lg:px-4 lg:mt-2 lg:mb-4 lg:w-full">
    <form id="search-form" class="my-auto flex-1 lg:border lg:border-solid lg:border-gray-200">
        <div class="input-group table bg-gray-100 lg:bg-white w-full">
            <input id="search-input" type="text" placeholder="搜索" class="inline-block w-full bg-gray-100 lg:bg-white">
            <span class="table-cell">
                <button name="search tigger button" disabled>
                    <i class="iconfont icon-search m-2"></i>
                </button>
            </span>
        </div>
    </form>
        
<script id="search-teamplate" type="text/html" data-path="/content.json">
    <div>
        <div class="search-header bg-gray-400">
            <input id="actual-search-input" model="keyword" ref="input" class="inline-block w-full h-10 px-2 py-1" placeholder="搜索" type="text">
        </div>
        <div class="search-result bg-gray-200">
            {{#each searchPosts}}
            <a href="/{{ path }}" class="result-item block px-2 pb-3 mb-1 pt-1 hover:bg-indigo-100">
                <i class="iconfont icon-file"></i>
                <h1 class="result-title inline font-medium text-lg">{{ title }}</h1>
                <p class="result-content text-gray-600 text-sm">{{{ text }}}</p>
            </a>
            {{/each}}
        </div>
    </div>
</script>

</div>


        <button name="menu toogle button" id="menu-toggle-btn" class="block sm:hidden p-3" role="button" aria-expanded="false">
            <i class="iconfont icon-hamburger"></i>
        </button>
    </div>
    <nav id="menu-nav" class="hidden sm:flex flex-col">
        
        
            <div class="menu-item menu-home" role="menuitem">
                <a href="/.">
                    <i class="iconfont icon-home" aria-hidden="true"></i>
                    <span class="menu-title">首页</span>
                </a>
            </div>
        
        
            <div class="menu-item menu-archives" role="menuitem">
                <a href="/archives">
                    <i class="iconfont icon-archive" aria-hidden="true"></i>
                    <span class="menu-title">归档</span>
                </a>
            </div>
        
        
            <div class="menu-item menu-categories" role="menuitem">
                <a href="/categories">
                    <i class="iconfont icon-folder" aria-hidden="true"></i>
                    <span class="menu-title">分类</span>
                </a>
            </div>
        
        
            <div class="menu-item menu-tags" role="menuitem">
                <a href="/tags">
                    <i class="iconfont icon-tag" aria-hidden="true"></i>
                    <span class="menu-title">标签</span>
                </a>
            </div>
        
        
            <div class="menu-item menu-repository" role="menuitem">
                <a href="/repository">
                    <i class="iconfont icon-project" aria-hidden="true"></i>
                    <span class="menu-title">项目</span>
                </a>
            </div>
        
        
            <div class="menu-item menu-links" role="menuitem">
                <a href="/links">
                    <i class="iconfont icon-friend" aria-hidden="true"></i>
                    <span class="menu-title">友链</span>
                </a>
            </div>
        
        
            <div class="menu-item menu-about" role="menuitem">
                <a href="/about">
                    <i class="iconfont icon-cup" aria-hidden="true"></i>
                    <span class="menu-title">关于</span>
                </a>
            </div>
        
        
<div class="social-links flex sm:flex-col lg:hidden mt-5">
    
        <span class="social-item text-center">
            <a target="_blank" rel="noopener" href="https://github.com/lushunming">
                <i class="iconfont social-icon icon-github"></i>
                <span class="menu-title hidden lg:inline">menu.github</span>
            </a>
        </span>
    
        <span class="social-item text-center">
            <a href="/atom.xml">
                <i class="iconfont social-icon icon-rss"></i>
                <span class="menu-title hidden lg:inline">menu.rss</span>
            </a>
        </span>
    
</div>


    </nav>
</header>

        <section class="main-section">
            
    <main class="flex-1 px-4 py-12 md:px-5 lg:px-8 lg:py-4 relative min-h-screen">
    

    <article class="content article article-archives article-type-list" itemscope="">
        <header class="article-header">
            
    
        <h1 class="article-title text-lg" itemprop="name">
            shadowsocks安装以及kcptun加速
        </h1>
    



            <p class="article-meta mb-3 text-xs">
                <span class="article-date">
    <i class="iconfont icon-calendar-check"></i>
	<a href="/2017/03/09/linux/2017-03-09-shadowsocks%E5%AE%89%E8%A3%85%E4%BB%A5%E5%8F%8Akcptun%E5%8A%A0%E9%80%9F/" class="article-date">
	  <time datetime="2017-03-08T16:00:00.000Z" itemprop="datePublished">3月 9</time>
	</a>
</span>

                
    <span class="article-category">
    <i class="iconfont icon-folder"></i>
    <a class="article-category-link" href="/categories/linux/">linux</a>
  </span>


                
    <span class="article-tags">
    <i class="iconfont icon-tag"></i>
    <a class="article-tag-none-link" href="/tags/linux/" rel="tag">linux</a>, <a class="article-tag-none-link" href="/tags/shadowsocks/" rel="tag">shadowsocks</a>
  </span>


                <span class="_partial/post-comment"><i class="icon icon-comment"></i>
                    <a href="/2017/03/09/linux/2017-03-09-shadowsocks%E5%AE%89%E8%A3%85%E4%BB%A5%E5%8F%8Akcptun%E5%8A%A0%E9%80%9F/#comments" class="article-comment-link">
                        评论
                    </a>
                </span>
                

            </p>
        </header>
        <div class="marked-body article-body">
            <h1>shadowsocks安装以及kcptun加速</h1>
<p>最近买了搬瓦工的vps，因为搬瓦工很便宜而且可以一键安装，所以选了他，但是缺点是速度不快。经过研究发现可以很快搭建一个快速的梯子。</p>
<p>为了方便所以我都是选择一键安装的脚本。</p>
<ol>
<li>
<p>一键安装shadowsocks</p>
  <figure class="highlight vim"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">wget --<span class="keyword">no</span>-check-certificate http<span class="variable">s:</span>//raw.githubusercontent.<span class="keyword">com</span>/teddysun/shadowsocks_install/master/shadowsocks-<span class="keyword">go</span>.<span class="keyword">sh</span></span><br><span class="line">chmod +<span class="keyword">x</span> shadowsocks-<span class="keyword">go</span>.<span class="keyword">sh</span></span><br><span class="line">./shadowsocks-<span class="keyword">go</span>.<span class="keyword">sh</span> <span class="number">2</span>&gt;&amp;<span class="number">1</span> | tee shadowsocks-<span class="keyword">go</span>.<span class="built_in">log</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p>输入下面命令就会显示</p>
 <figure class="highlight oxygene"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">Congratulations, shadowsocks-go install completed!</span><br><span class="line">Your Server IP:your_server_ip</span><br><span class="line">Your Server Port:<span class="number">8989</span></span><br><span class="line">Your Password:your_password</span><br><span class="line">Your Local Port:<span class="number">1080</span></span><br><span class="line">Your Encryption <span class="function"><span class="keyword">Method</span>:</span>aes-<span class="number">256</span>-cfb</span><br><span class="line">Welcome <span class="keyword">to</span> visit:http:<span class="comment">//teddysun.com/392.html</span></span><br><span class="line">Enjoy it!</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p>就是安装完了。<br>
这个脚本默认已经安装开机自启动，</p>
 <figure class="highlight awk"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">启动：<span class="regexp">/etc/i</span>nit.d/shadowsocks start</span><br><span class="line">停止：<span class="regexp">/etc/i</span>nit.d/shadowsocks stop</span><br><span class="line">重启：<span class="regexp">/etc/i</span>nit.d/shadowsocks restart</span><br><span class="line">状态：<span class="regexp">/etc/i</span>nit.d/shadowsocks status</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p>以上是对shadowsocks的操作。</p>
</li>
<li>
<p>安装kcptun server</p>
 <figure class="highlight awk"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">wget --no-check-certificate https:<span class="regexp">//</span>raw.githubusercontent.com<span class="regexp">/kuoruan/</span>kcptun_installer<span class="regexp">/master/</span>kcptun.sh</span><br><span class="line">chmod +x ./kcptun.sh</span><br><span class="line">./kcptun.sh</span><br></pre></td></tr></table></figure>
<p>比较重要的是设置加速端口，一定是你的shadowsocks端口才行。设置错误也没有什么关系，可以修改配置文件。</p>
</li>
<li>
<p>修改配置文件</p>
<p>首先是修改shadowsocks配置文件</p>
 <figure class="highlight awk"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vim <span class="regexp">/etc/</span>shadowsocks/config.json</span><br></pre></td></tr></table></figure>
<p>显示是：</p>
 <figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">        <span class="attr">&quot;server&quot;</span>:<span class="string">&quot;0.0.0.0&quot;</span>,</span><br><span class="line">        <span class="attr">&quot;server_port&quot;</span>:<span class="number">65534</span>, <span class="comment">//服务端的端口，将来要用来配置kcptun。</span></span><br><span class="line">        <span class="attr">&quot;local_port&quot;</span>:<span class="number">1080</span>,</span><br><span class="line">        <span class="attr">&quot;password&quot;</span>:<span class="string">&quot;你的密码&quot;</span>,</span><br><span class="line">        <span class="attr">&quot;method&quot;</span>:<span class="string">&quot;aes-256-cfb&quot;</span>,</span><br><span class="line">        <span class="attr">&quot;timeout&quot;</span>:<span class="number">600</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>然后重启shadowsocks服务。</p>
 <figure class="highlight awk"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="regexp">/etc/i</span>nit.d/shadowsocks restart</span><br></pre></td></tr></table></figure>
<p>然后修改kcptun的配置文件。</p>
 <figure class="highlight awk"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vim <span class="regexp">/usr/</span>local<span class="regexp">/kcp-server/</span>server-kcptun.json</span><br></pre></td></tr></table></figure>
<p>显示是：</p>
 <figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">        <span class="attr">&quot;listen&quot;</span>: <span class="string">&quot;:45678&quot;</span>, <span class="comment">//监听端口随意选一个</span></span><br><span class="line">        <span class="attr">&quot;target&quot;</span>: <span class="string">&quot;127.0.0.1:65534&quot;</span>,<span class="comment">//加速的端口就是你的shadowsocks的服务端口</span></span><br><span class="line">        <span class="attr">&quot;key&quot;</span>: <span class="string">&quot;你的kcptun密码&quot;</span>,</span><br><span class="line">        <span class="attr">&quot;mode&quot;</span>: <span class="string">&quot;fast2&quot;</span>,</span><br><span class="line">        <span class="attr">&quot;mtu&quot;</span>: <span class="number">1350</span>,</span><br><span class="line">        <span class="attr">&quot;sndwnd&quot;</span>: <span class="number">1024</span>,</span><br><span class="line">        <span class="attr">&quot;rcvwnd&quot;</span>: <span class="number">1024</span>,</span><br><span class="line">        <span class="attr">&quot;nocomp&quot;</span>: <span class="literal">false</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>重新启动kcptun</p>
 <figure class="highlight ebnf"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="attribute">supervisorctl restart kcptun</span></span><br></pre></td></tr></table></figure>
<p>服务端的配置就结束了</p>
</li>
<li>
<p>本地配置</p>
<p>在你的电脑上你需要先下载shadowsocks的客户端和kcptun的客户端。<br>
在kcptun客户端的目录中新建一个json文件<code>conf.json</code>,内容是：</p>
 <figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">        <span class="attr">&quot;localaddr&quot;</span>: <span class="string">&quot;:12948&quot;</span>, <span class="comment">//本地端口，在shadowsocks客户端配置要用</span></span><br><span class="line">        <span class="attr">&quot;remoteaddr&quot;</span>: <span class="string">&quot;162.211.225.21:45678&quot;</span>,<span class="comment">//要和服务端监听的端口一致（vps ip+listen）。</span></span><br><span class="line">        <span class="attr">&quot;key&quot;</span>: <span class="string">&quot;kcptun的密码&quot;</span>,</span><br><span class="line">        <span class="attr">&quot;mode&quot;</span>: <span class="string">&quot;fast2&quot;</span>,</span><br><span class="line">        <span class="attr">&quot;conn&quot;</span>: <span class="number">3</span>,</span><br><span class="line">        <span class="attr">&quot;autoexpire&quot;</span>: <span class="number">60</span>,</span><br><span class="line">        <span class="attr">&quot;mtu&quot;</span>: <span class="number">1350</span>,</span><br><span class="line">        <span class="attr">&quot;sndwnd&quot;</span>: <span class="number">1024</span>,</span><br><span class="line">        <span class="attr">&quot;rcvwnd&quot;</span>: <span class="number">1024</span>,</span><br><span class="line">        <span class="attr">&quot;datashard&quot;</span>: <span class="number">10</span>,</span><br><span class="line">        <span class="attr">&quot;parityshard&quot;</span>: <span class="number">3</span>,</span><br><span class="line">        <span class="attr">&quot;dscp&quot;</span>: <span class="number">0</span>,</span><br><span class="line">        <span class="attr">&quot;nocomp&quot;</span>: <span class="literal">false</span>,</span><br><span class="line">        <span class="attr">&quot;acknodelay&quot;</span>: <span class="literal">false</span>,</span><br><span class="line">        <span class="attr">&quot;nodelay&quot;</span>: <span class="number">0</span>,</span><br><span class="line">        <span class="attr">&quot;interval&quot;</span>: <span class="number">20</span>,</span><br><span class="line">        <span class="attr">&quot;resend&quot;</span>: <span class="number">2</span>,</span><br><span class="line">        <span class="attr">&quot;nc&quot;</span>: <span class="number">1</span>,</span><br><span class="line">        <span class="attr">&quot;sockbuf&quot;</span>: <span class="number">4194304</span>,</span><br><span class="line">        <span class="attr">&quot;keepalive&quot;</span>: <span class="number">10</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>我不需要加密，所以kcptun的加密被我删了。<br>
在kcptun客户端目录下：</p>
 <figure class="highlight arduino"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">client_linux_amd64 -c <span class="built_in">config</span>.json</span><br></pre></td></tr></table></figure>
<p>然后开启shadowsocks客户端，</p>
 <figure class="highlight angelscript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">serverAddress：<span class="number">127.0</span><span class="number">.0</span><span class="number">.1</span></span><br><span class="line">port：kcptun 客户端的localaddr</span><br><span class="line">加密和密码和服务端shadowdocks的加密和密码一样</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p>这样启动就可以了。<br>
其实就相当于shadowsocks服务端和kcptun服务端连接，shadowsocks客户端和kcptun客户端相连。kcptun服务端和客户端相互通信，而不是shadowsocks的服务端和客户端通信。如下图<br>
<img src="https://raw.githubusercontent.com/xtaci/kcptun/master/kcptun.png" alt="加速原理"><br>
到此就结束了。</p>
</li>
</ol>

        </div>
        
<blockquote class="copyright">
    <p><strong>本文链接 : </strong><a class="permalink" href="http://www.lushunming.com.cn/2017/03/09/linux/2017-03-09-shadowsocks%E5%AE%89%E8%A3%85%E4%BB%A5%E5%8F%8Akcptun%E5%8A%A0%E9%80%9F/">http://www.lushunming.com.cn/2017/03/09/linux/2017-03-09-shadowsocks安装以及kcptun加速/</a></p>
    <p><strong>This article is available under <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank" rel="noopener noreferrer">Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)</a> License</strong></p>
</blockquote>


    </article>
    
    <section id="comments">
        

        
    </section>


    

</main>


<aside style="" id="sidebar" class="aside aside-fixture">
    <div class="toc-sidebar">
        <nav id="toc" class="article-toc">
            <h3 class="toc-title">文章目录</h3>
            <ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link"><span class="toc-number">1.</span> <span class="toc-text">shadowsocks安装以及kcptun加速</span></a></li></ol>
        </nav>
    </div>
</aside>





        </section>
        <footer class="hidden lg:block fixed bottom-0 left-0 sm:w-1/12 lg:w-1/6 bg-gray-100 z-40">
    
    <div class="footer-social-links">
        
            <a target="_blank" rel="noopener" href="https://github.com/lushunming">
                <i class="iconfont icon-github"></i>
            </a>
        
            <a href="/atom.xml">
                <i class="iconfont icon-rss"></i>
            </a>
        
    </div>
    
    
</footer>

        <div id="mask" class="hidden mask fixed inset-0 bg-gray-900 opacity-75 z-40"></div>
        <div id="search-view-container" class="hidden shadow-xl"></div>
        
<script src="/js/dom-event.min.js"></script>

<script src="//cdn.jsdelivr.net/npm/yox@1.0.0-alpha.121/dist/standard/prod/yox.min.js"></script>


<script src="/js/search.min.js"></script>


    <script src="//cdn.jsdelivr.net/npm/gitalk@1.5.2/dist/gitalk.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/blueimp-md5@2.10.0/js/md5.min.js"></script>
<script type="text/javascript">
    var gitalk = new Gitalk({
        clientID: 'd76d74420825181b7018',
        clientSecret: '8b9c3676695fa33d6b10d9697a96ef27c8301930',
        repo: 'blog-comment',
        owner: 'lushunming',
        admin: ['lushunming'],
        id: md5(location.pathname),
        distractionFreeMode: true
    })
    gitalk.render('comments')
</script>



    <script src="//cdn.jsdelivr.net/npm/lightgallery.js@1.1.3/dist/js/lightgallery.min.js"></script>
    
<script src="/js/light-gallery.min.js"></script>





    </body>
</html>
